Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
How To Solve "Expected type object but found type string" in REST API calls? (reactjs, javascript)

I'm trying to use following Auth0 API call: https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id

const sUserMetadata = async () => {
                const domain = "xxxxxxxxxxxxxxx"

                try {
                    const accessToken = await getAccessTokenSilently({
                        audience: `${domain}/api/v2/`,
                        scope: "update:current_user_metadata",
                    });


                    const userDetailsByIdUrl = `${domain}/api/v2/users/${user.sub}`;
                    const metadataResponse = await fetch(userDetailsByIdUrl, {
                        method: 'PATCH',
                        headers: {
                            Authorization: `Bearer ${accessToken}`,
                        },
                        body: { "email_verified": true }
                    })

                    let user_metadata = await metadataResponse;
                    console.log(user_metadata)
                } catch (e) {
                    console.log(e.message);
                }
            };

            sUserMetadata().then(r => null);

I am receiving following response error:

{"statusCode":400,"error":"Bad Request","message":"Payload validation error: 'Expected type object but found type string'.","errorCode":"invalid_body"}

Obviously the Body-Tag provides it in the correct form with Bracets {} so it Should! be an Object.

I have tried:

  • JSON.parse()

  • I have tried to add Content-Type which results in a freaking "SYNTAX ERROR" because of the - in content-type which doesnt make any sense because under chrome debugger I can obviously see that there is a property called content-type: text/plain;charset=UTF-8 and I have no idea how else I am supposed to change this?

    headers: {
                 Authorization: `Bearer ${accessToken}`,
                 Content-Type: 'application/json',
             },
    
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Putting Content-Type inside Apostrophes 'Content-Type' so it doesn't give a Syntax Error and then you using JSON.Stringify() at the Body-Tag part fixes the problem.

const metadataResponse = await fetch(userDetailsByIdUrl, {
                        method: 'PATCH',

                        headers: {
                            Authorization: `Bearer ${accessToken}`,
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify({ "user_metadata" : { "addresses": {"work_address": "100 Industrial Way"} }}),
                    })

PS: save me from javascript pls

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda